import { PipeTransform, Injectable, ArgumentMetadata, BadRequestException } from '@nestjs/common';

@Injectable()
export class NullArrayToNull implements PipeTransform {
  private objectAtt: string []
  constructor(strAtt : string []) {
    this.objectAtt = strAtt
  }
  
  transform(value: any, metadata: ArgumentMetadata): any {
    if(metadata.type === 'body') {
      this.objectAtt.forEach(item => {
        if(value.hasOwnProperty(item) && value[item].length === 0) {
          value[item] = null
          console.log(value);
        }
      })
    }
    return value;
  }
}

